//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package net.mingsoft.mdiy.action.web;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.mingsoft.base.entity.ResultData;
import net.mingsoft.mdiy.action.BaseAction;
import net.mingsoft.mdiy.biz.IModelBiz;
import net.mingsoft.mdiy.entity.ModelEntity;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Api(
        tags = {"前端-自定义模块接口"}
)
@Controller("webFormAction")
@RequestMapping({"/mdiy/form"})
public class FormAction extends BaseAction {
    @Autowired
    private IModelBiz modelBiz;

    public FormAction() {
    }

    @ApiOperation("根据模型名称获取渲染表单")
    @ApiImplicitParams({@ApiImplicitParam(
            name = "modelName",
            value = "模型名称",
            required = true,
            paramType = "query"
    )})
    @GetMapping({"/get"})
    @ResponseBody
    public ResultData get(String modelName, HttpServletResponse response, HttpServletRequest request) {
        if (StringUtils.isBlank(modelName)) {
            return ResultData.build().error();
        } else {
            QueryWrapper<ModelEntity> queryWrapper = new QueryWrapper();
            queryWrapper.like("model_name", modelName);
            ModelEntity model = (ModelEntity)this.modelBiz.getOne(queryWrapper);
            return model != null && Boolean.parseBoolean(((Map)JSONUtil.toBean(model.getModelJson(), Map.class)).get("isWebSubmit").toString()) ? ResultData.build().success(model) : ResultData.build().error("此业务不允许外部提交");
        }
    }
}
